using System;

namespace System.Resources.SqlResource
{
    public enum SqlResourceExportType
    { 
        Resource,
        ResourceX
    }

    public sealed class SqlResourceWriter : IResourceWriter
    {
        private readonly Globalization.CultureInfo _ci = null;

        public SqlResourceWriter(Globalization.CultureInfo ci)
        {
            _ci = ci;
        }

        public void AddResource(string name, byte[] value)
        {
            CSUtil u = new CSUtil();
            ISqlResourceGetData s = u.CreateInstance();
            string ParamType;
            ParamType = value.GetType().AssemblyQualifiedName;
            s.SetResource(_ci, name, null, value, ParamType);
        }

        public void AddResource(string name, object value)
        {
            CSUtil u = new CSUtil();
            ISqlResourceGetData s = u.CreateInstance();
            string ParamType;
            byte[] ParamObjectValue;
            ParamType = value.GetType().AssemblyQualifiedName;
            ParamObjectValue = ObjectByteArrayConverter.ObjectToByteArray(value);
            s.SetResource(_ci, name, null, ParamObjectValue, ParamType);
        }

        public void AddResource(string name, string value)
        {
            CSUtil u = new CSUtil();
            ISqlResourceGetData s = u.CreateInstance();
            string ParamType;
            ParamType = value.GetType().AssemblyQualifiedName;
            s.SetResource(_ci, name, value, null, ParamType);
        }

        public void DeleteResource(string name)
        {
            CSUtil u = new CSUtil();
            ISqlResourceGetData s = u.CreateInstance();
            s.DelResource(_ci, name);
        }

        public void Close()
        {
            return;
        }

        public void Dispose()
        {
            Close();
        }

        public void ExportResource(SqlResourceExportType ExportType, string FileName)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public void Generate()
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
